import React from 'react';
import { Result } from 'antd';

class ChartErrorBoundary extends React.Component {
  constructor(props: any) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error: any) {
    return { hasError: true };
  }

  componentDidCatch(error: any, errorInfo: any) {
    // 你可以在这里记录错误日志
    console.error('Uncaught error:', error, errorInfo);
  }

  render() {
    // @ts-ignore
    if (this.state.hasError) {
      return <Result status="error" title="图表渲染异常" />;
    }

    // @ts-ignore
    return this.props.children;
  }
}

export default ChartErrorBoundary;
